﻿using TSharp.Core.Exceptions;
using TSharp.Core.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using TSharp.Core.TestUtil;
using System.Diagnostics;
using TSharp.Core.Osgi; 

namespace TSharp.CoreTests
{


    /// <summary>
    ///这是 IniHelperTest 的测试类，旨在
    ///包含所有 IniHelperTest 单元测试
    ///</summary>
    [TestClass()]
    public class IniHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        public class Test
        {
            public string B { get; set; }
            public int C { get; set; }
        }


        [TestMethod()]
        public void DeserializeTest()
        {
            IniHelper target = IniHelper.Current;
            Test a = new Test()
            {
                B = "bbbb",
                C = 12345
            };
            Test b = new Test();
            target.Deserialize(b);

            Assert.AreEqual(a.B, b.B);
            Assert.AreEqual(a.C, b.C);
        }
        [TestMethod()]
        public void SerializeTest()
        {
            Performance.MeasurePerformance(x =>
            {
                IniHelper target = IniHelper.Current;
                Test a = new Test()
                {
                    B = "bbbb",
                    C = 1234
                };
                target.Serialize(a);
                return 0;
            }, 3, 30);

        }
        [TestMethod()]
        public void SetTest()
        {
            IniHelper target = IniHelper.Current;
            target.Set("test", "aaaa");
        }
        [TestMethod()]
        public void STest()
        {
            Level l = Level.THREAD | Level.ROOT;

            Console.WriteLine(l.ToStringObject());
            Console.WriteLine(l.ToString());
            Console.WriteLine(Convert.ToString(l));
            Console.WriteLine(l.HasFlag(Level.SESSION));
            Console.WriteLine(l.HasFlag(Level.THREAD));
            Console.WriteLine(l.HasFlag(Level.ROOT));

            switch (l)
            {
                case Level.REQUSET:
                    Console.WriteLine("REQUSET");
                    break;
                case Level.SESSION:
                    Console.WriteLine("SESSION");
                    break;
                case Level.ROOT:
                    Console.WriteLine("ROOT");
                    break;
                case Level.THREAD:
                    Console.WriteLine("THREAD");
                    break;
                default:
                    Console.WriteLine("default");
                    break;
            }

        }
        /// <summary>
        ///Get 的测试
        ///</summary>
        [TestMethod()]
        public void GetTest()
        {
            IniHelper target = IniHelper.Current; // TODO: 初始化为适当的值
            string key = "test";
            string expected = "aaaa";
            string actual = null;
            Action<string> doGet = x =>
            {
                actual = x;
            }; // TODO: 初始化为适当的值

            target.Get(key, doGet);
            Assert.AreEqual(expected, actual);
        }
    }
}
